//
//  PPShareView.m
//  pickpic
//
//  Created by 胡文广 on 2017/5/1.
//  Copyright © 2017年 MicroDream. All rights reserved.
//

#import "PPShareView.h"
#import "PPHomeAlbumModel.h"
#import "UIImage+Resize.h"
#import "PPTemplateModel.h"
#import "PPTemplateCoverFrame.h"
#import "PPHomeAlbumModel.h"
#import "PPTemplateShareModel.h"
#import "UIImage+PPImage.h"

#import "UIImage+ImageEffects.h"

#define kNormalShareTitleFont [UIFont boldSystemFontOfSize:24]
#define kNormalShareTitleLineDistance 10

@interface PPShareView()

@property (nonatomic,strong) UIImageView *albumPhotoView;


@property (nonatomic,strong) UILabel *albumTitleLabel;

@property (nonatomic,strong) UIImageView *userIcon;

@property (nonatomic,strong) UILabel *userLabel;

@property (nonatomic,strong) UIImageView *coverImageView;
@property (nonatomic,strong) UIScrollView *coverScrollView;
@property (nonatomic,strong) UIImageView *toastView;
@property (nonatomic,strong) UIBlurEffect *blur;
@property (nonatomic,strong) UIImage *img;
@end
@implementation PPShareView
- (UIImageView *)toastView{

    if (!_toastView) {
        _toastView = [[UIImageView alloc] init];
        _toastView.image = [UIImage imageNamed:@"ebookToastView"];
    }
    return _toastView;
}
- (UIScrollView *)coverScrollView{

    if (!_coverScrollView) {
        _coverScrollView = [[UIScrollView alloc] init];
        _coverScrollView.userInteractionEnabled = NO;
        
    }
    return _coverScrollView;
}
- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
//        self.contentMode = UIViewContentModeScaleAspectFill;
        

    }
    return self;
}
- (instancetype)init{

    if (self = [super init]) {
        
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAlbumPic:) name:PPNotice_ChangeAlbumsPic object:nil];
        


    }
    return self;
}
- (void)updateCoverImage:(UIImage *)img{

//    self.coverImageView.contentMode = UIViewContentModeScaleAspectFit;
//    self.coverImageView.contentMode = UIViewContentModeScaleToFill;
//    self.coverImageView.image = img;
    
//    return;
    
    
    if ([self.tempModel.series isEqualToString:@"wave"]) {
         self.coverImageView.image = img;
        
        CGFloat ratio = (double)img.size.height/(double)img.size.width;
        CGFloat bigW = self.tempModel.shareModel.shareBoxWidth;
        CGFloat bigH = self.tempModel.shareModel.shareBoxWidth*ratio;
        
        CGFloat sum = 0;
        if (bigH < self.tempModel.shareModel.shareBoxWidth) {
            sum = ( self.tempModel.shareModel.shareBoxWidth - bigH);
            
        }else if(bigW < self.tempModel.shareModel.shareBoxHeight){
            sum = (self.tempModel.shareModel.shareBoxHeight - bigH);
        }
        
        bigH = bigH + sum;
        bigW = bigW + sum;
        self.coverImageView.bounds = CGRectMake(0, 0, bigW, bigH);
        self.coverImageView.center = CGPointMake(self.tempModel.shareModel.shareBoxWidth/2, (self.tempModel.shareModel.shareBoxHeight)/2);
        return ;
    }
    
    CGFloat ratio = (double)img.size.height/(double)img.size.width;
    CGFloat bigW = self.tempModel.shareModel.shareBoxWidth;
    CGFloat bigH = self.tempModel.shareModel.shareBoxWidth*ratio;
    
    CGFloat coverImgY = 0;
    if (bigH > self.tempModel.shareModel.shareBoxHeight) {
        
        self.coverScrollView.contentOffset = CGPointMake(0, (bigH - self.tempModel.shareModel.shareBoxHeight)/2);
    }else if (bigH < _tempModel.shareModel.shareBoxHeight){
        self.coverScrollView.contentOffset = CGPointMake(0, (self.tempModel.shareModel.shareBoxHeight - bigH)/2);
        
        coverImgY = (self.tempModel.shareModel.shareBoxHeight - bigH)/2;
    }
    
     self.coverImageView.image = img;
    
    self.coverImageView.frame = CGRectMake(0,coverImgY, bigW, bigH);
    self.coverScrollView.contentSize = CGSizeMake(self.width,bigH);
    

    
    
    
}

- (UIImageView *)coverImageView{
    
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] init];
        _coverImageView.clipsToBounds = YES;
        _coverImageView.backgroundColor = CLEAR;
        _coverImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(previewAlbum:)];
        [_coverImageView addGestureRecognizer:tap];
    }
    return _coverImageView;
}
- (UIImageView *)albumPhotoView{

    if (!_albumPhotoView) {
        _albumPhotoView = [[UIImageView alloc] init];
        _albumPhotoView.layer.shadowColor = [UIColor blackColor].CGColor;//阴影颜色
        _albumPhotoView.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
        _albumPhotoView.layer.shadowOpacity = 2.0;//不透明度
        _albumPhotoView.layer.shadowRadius = 5;//半径
        _albumPhotoView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(previewAlbum:)];
        [_albumPhotoView addGestureRecognizer:tap];
    }
    return _albumPhotoView;
}
- (UILabel *)albumTitleLabel{

    if (!_albumTitleLabel) {
        _albumTitleLabel = [[UILabel alloc] init];
        _albumTitleLabel.textAlignment = NSTextAlignmentCenter;
        _albumTitleLabel.numberOfLines = 2;
        _albumTitleLabel.textColor = WHITE;
        _albumTitleLabel.backgroundColor = CLEAR;
    }
    return _albumTitleLabel;
}
- (UILabel *)userLabel{
    
    if (!_userLabel) {
        _userLabel = [[UILabel alloc] init];
        _userLabel.backgroundColor = CLEAR;
        _userLabel.font = PPFONTSIZE(12);
        _userLabel.textColor = WHITE;
    }
    return _userLabel;
}
//- (UILabel *)pickpicNum{
//    
//    if (!_pickpicNum) {
//        _pickpicNum = [[UILabel alloc] init];
//    }
//    return _pickpicNum;
//}
- (UIImageView *)userIcon{
    
    if (!_userIcon) {
        _userIcon = [[UIImageView alloc] init];
        _userIcon.backgroundColor =CLEAR;
        _userIcon.layer.cornerRadius = 12.0f;
        _userIcon.layer.masksToBounds = YES;
        
    }
    return _userIcon;
}
///MARK:分享页 默认样式
- (void)setAlbumModel:(PPHomeAlbumModel *)albumModel{

    
    
    for (UIView  *v in self.subviews) {
        [v removeFromSuperview];
    }
    
    _albumModel = albumModel;
    
    self.coverScrollView.backgroundColor = CLEAR;
    self.coverScrollView.layer.masksToBounds = YES;
    self.coverScrollView.layer.cornerRadius = 0;
    
    self.userIcon.hidden = self.shareType == PPShareViewTypeNone;
    
    self.userLabel.textAlignment = NSTextAlignmentCenter;
    
    if (self.shareType == PPShareViewTypeNone) {
            self.albumPhotoView.image = [_albumModel.coverImage getSubImage:CGRectMake(0, 0, self.width - 120, self.height - 120-136)];
            self.albumTitleLabel.textColor = WHITE;
            self.albumTitleLabel.font = kNormalShareTitleFont;
            self.userLabel.textColor = WHITE;
        
        // blur
        self.image = albumModel.coverImage;
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
        effectview.frame = CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT);
        [self addSubview:effectview];
        
    }else{
//        self.albumPhotoView.contentMode = UIViewContentModeScaleAspectFill;
//         self.albumPhotoView.image = _albumModel.image;
    }
    
    self.albumTitleLabel.layer.shadowColor = [UIColor clearColor].CGColor;
    
    [self.albumTitleLabel changeLineSpaceForLabelWithSpace:kNormalShareTitleLineDistance/2-kLabelMargin text:_albumModel.title labelFont:kNormalShareTitleFont];
    

    CGFloat width = 0;
    if (IS_IPHONE_6) {
        width = self.width - 124;
    }else if (IS_IPHONE_6_PLUS){
        width = self.width - 67*2;
    }else{
        width = self.width - 120;
    }
//    self.albumTitleLabel.backgroundColor = RED;
    
    
    //设置分享也标题的对齐方式
    [self.albumTitleLabel textLabelAlbumtitle:_albumModel.title  width:width];
    
    
    if (_albumModel.userUrl) {
        [self.userIcon sd_setImageWithURL:[NSURL URLWithString:_albumModel.userUrl]];
    }else{
        self.userIcon.image = _albumModel.userIcon;
    }

    PPAccountProfiles *profiles = [PPAccountManager sharedInstance].account.profiles;
//    self.albumModel.nickName = profiles.name;
    self.userLabel.text = profiles.name;

    [self addSubview:self.albumPhotoView];

    [self.albumPhotoView addSubview:self.albumTitleLabel];

    [self.albumPhotoView addSubview:self.userLabel];

//    [self showToast];
}
- (void)showToast{

//    if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"saveFirst"] boolValue]) {
    
        [self addSubview:self.toastView];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDelegate:self];
            [UIView setAnimationDuration:1.0f];
            [self.toastView setAlpha:0.0f];
            [UIView commitAnimations];
            
            [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"saveFirst"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        });
//    }
    
}
- (void)layoutSubviews{

    [super layoutSubviews];
    
    if (self.shareType == PPShareViewTypeNone) {
        
        CGFloat toastY = 0;
        CGFloat  difference = 0;
        if (IS_IPHONE_6) {
            self.albumPhotoView.frame = CGRectMake(62, 58, self.width - 124, 402);
            difference = 124;
            toastY = 244;
        }else if (IS_IPHONE_6_PLUS){
            self.albumPhotoView.frame = CGRectMake(67,68, self.width - 67*2, 448);
            difference = 67*2;
            toastY = 274;
        }else{
            self.albumPhotoView.center = CGPointMake(self.center.x, (self.height-136)/2);
            self.albumPhotoView.bounds = CGRectMake(0, 0, self.width - 120, self.height - 120-136);
            difference = 120;
            
            toastY = 214;
        }
        
        CGFloat multiple = 28.2;
        
        self.albumTitleLabel.frame = CGRectMake(multiple, 0,self.albumPhotoView.width - multiple*2,self.albumPhotoView.height);
        
        self.userIcon.frame = CGRectMake(25,self.albumPhotoView.height-35, 24, 17);
        
        self.userLabel.frame = CGRectMake(14,self.albumPhotoView.height-17-24, self.width - 120 - 14*2,17);
        
        CGFloat w = 175;
        CGFloat h = 50;
        if (IS_IPHONE_5) {
            w = 160;
            h = 45;
        }
        self.toastView.bounds = CGRectMake(0, 0,self.toastView.image.size.width, self.toastView.image.size.height);
        self.toastView.center = CGPointMake(self.centerX, toastY);
        
        
    }else{
    
        PPTemplateShareModel *shareM =  self.tempModel.shareModel;

     
        CGFloat H = shareM.shareBoxHeight;
        CGFloat y = shareM.shareBoxYaxis;
        if ([_tempModel.series isEqualToString:@"wave"]) {
            H = shareM.shareBoxWidth;
            
            y = shareM.shareBoxYaxis - 64;

            if (_tempModel.orderNum == 6) {
                y = shareM.shareBoxYaxis - 64 - 20;
                if (IS_IPHONE_6_PLUS) {
                    y = shareM.shareBoxYaxis - 64;
                }
            }else if (_tempModel.orderNum == 7){
                
                y = shareM.shareBoxYaxis - 64 - 20;
                if (IS_IPHONE_6_PLUS) {
                    y = shareM.shareBoxYaxis - 64 - 8;
                }
            }
    
        }
        
        self.coverScrollView.frame = CGRectMake(shareM.shareBoxXaxis, y, shareM.shareBoxWidth, H);

        if ([_tempModel.series isEqualToString:@"wave"]) {
            
            
            
            CGFloat ratio = (double)self.albumModel.eBookCoverImage.size.height/(double)self.albumModel.eBookCoverImage.size.width;
            CGFloat bigW = self.tempModel.shareModel.shareBoxWidth;
            CGFloat bigH = self.tempModel.shareModel.shareBoxWidth*ratio;
            
            CGFloat sum = 0;
            if (bigH <  shareM.shareBoxWidth) {
                sum = ( shareM.shareBoxWidth - bigH);
                
            }else if(bigW < shareM.shareBoxHeight){
                sum = (shareM.shareBoxHeight - bigH);
            }
            
            bigH = bigH + sum;
            bigW = bigW + sum;
            
            self.coverImageView.bounds = CGRectMake(0, 0, bigW, bigH);
            self.coverImageView.center = CGPointMake(shareM.shareBoxWidth/2, (shareM.shareBoxHeight)/2);
            
//            CGFloat sum;
//            if (self.albumModel.eBookCoverImage.size.height < self.albumModel.eBookCoverImage.size.width) {
//                sum  = self.albumModel.eBookCoverImage.size.height - H;
//                CGFloat bigW = self.albumModel.eBookCoverImage.size.width - sum;
//                CGFloat bigH = self.albumModel.eBookCoverImage.size.height - sum;
//                //                }
//                PPLog(@"哈哈猴子 - %f --%f",shareM.shareBoxWidth,bigH);
//                self.coverImageView.frame = CGRectMake(-((bigW-H)/2), 0, bigW, bigH);
//
//            }else if(self.albumModel.eBookCoverImage.size.height > self.albumModel.eBookCoverImage.size.width){
//                sum = self.albumModel.eBookCoverImage.size.width - self.tempModel.shareModel.shareBoxWidth;
//
//                CGFloat bigW = self.albumModel.eBookCoverImage.size.width - sum/2;
//                CGFloat bigH = self.albumModel.eBookCoverImage.size.height - sum/2;
//                self.coverImageView.frame = CGRectMake(0,-((bigW-H)/2), bigW, bigH);
//            }else{
//                self.coverImageView.frame = self.coverScrollView.bounds;
//
//            }
        }
        //调整标题位置
       [self adjustShareAlbumtitleLabelH:shareM];
        
        [self adjustShareUserLabel:shareM];

        
        
//        self.pickpicNum.frame = CGRectMake(shareM.sharePickpicXaxis, shareM.sharePickpicYaxis, shareM.sharePickpicWidth, shareM.sharePickpicHeight);

    }
    
}

- (void)previewAlbum:(UITapGestureRecognizer *)rec{

    if (self.BlockTapPhotoView) {
        self.BlockTapPhotoView();
    }
}

///MARK: 电子相册模板
- (void)setTempModel:(PPTemplateModel *)tempModel{

    _tempModel = tempModel;

    [self.albumPhotoView removeFromSuperview];
    //
    [self.coverScrollView removeFromSuperview];
    self.coverScrollView = nil;
    [self.coverImageView removeFromSuperview];
    self.coverImageView = nil;
    
    if (self.shareType == PPShareViewTypeNone) {
        [self addSubview:self.albumPhotoView];
    }

    
    if (tempModel.shareUrl &&!(self.shareType == PPShareViewTypeNone)) {
        //电子书相框
      UIImage *coverImage =  [UIImage cacheShareCover:tempModel.shareUrl];
        if (!coverImage) {
            [self sd_setImageWithURL:[NSURL URLWithString:tempModel.shareUrl]];
        }else{
            self.image = coverImage;
            
        }

    }

    //电子书封面
    self.coverScrollView.backgroundColor = CLEAR;
    self.coverImageView.backgroundColor = CLEAR;
    
    //电子书封面
    [self addSubview:self.coverScrollView];
    

    [self.coverScrollView addSubview:self.coverImageView];

    if ([self.tempModel.series isEqualToString:@"wave"]) {
        self.coverImageView.image = self.albumModel.eBookCoverImage;

        CGFloat ratio = (double)self.albumModel.eBookCoverImage.size.height/(double)self.albumModel.eBookCoverImage.size.width;
        CGFloat bigW = self.tempModel.shareModel.shareBoxWidth;
        CGFloat bigH = self.tempModel.shareModel.shareBoxWidth*ratio;
        
        CGFloat sum = 0;
        if (bigH <self.tempModel.shareModel.shareBoxWidth) {
            sum = ( self.tempModel.shareModel.shareBoxWidth - bigH);
            
        }else if(bigW < self.tempModel.shareModel.shareBoxHeight){
            sum = (self.tempModel.shareModel.shareBoxHeight - bigH);
        }
        
        bigH = bigH + sum;
        bigW = bigW + sum;
        
        self.coverImageView.bounds = CGRectMake(0, 0, bigW, bigH);
        self.coverImageView.center = CGPointMake(self.tempModel.shareModel.shareBoxWidth/2, (self.tempModel.shareModel.shareBoxHeight)/2);
        
        self.coverScrollView.backgroundColor = WHITE;
        self.coverScrollView.layer.masksToBounds = YES;
        self.coverScrollView.layer.cornerRadius = self.tempModel.shareModel.shareBoxWidth/2;
        
    }else{
        
        CGFloat ratio = (double)self.albumModel.eBookCoverImage.size.height/(double)self.albumModel.eBookCoverImage.size.width;
        CGFloat bigW = _tempModel.shareModel.shareBoxWidth;
        CGFloat bigH = _tempModel.shareModel.shareBoxWidth*ratio;
        
        CGFloat coverImgY = 0;
        if (bigH > _tempModel.shareModel.shareBoxHeight) {
            
            self.coverScrollView.contentOffset = CGPointMake(0, (bigH - _tempModel.shareModel.shareBoxHeight)/2);
        }else if (bigH < _tempModel.shareModel.shareBoxHeight){
            self.coverScrollView.contentOffset = CGPointMake(0, (_tempModel.shareModel.shareBoxHeight - bigH)/2);
            
            coverImgY = (_tempModel.shareModel.shareBoxHeight - bigH)/2;
        }
        self.coverImageView.frame = CGRectMake(0,coverImgY, bigW, bigH);
        
        self.coverScrollView.contentSize = CGSizeMake(self.width,bigH);
        //    }
        self.coverImageView.image = self.albumModel.eBookCoverImage;
    }

    
    
//    if ([_tempModel.series isEqualToString:@"wave"]) {
//        self.coverScrollView.backgroundColor = WHITE;
//        self.coverScrollView.layer.masksToBounds = YES;
//        self.coverScrollView.layer.cornerRadius = bigW/2;
//    }
    
    //分享 标题、用户名
    [self setupShareTitleStyle:tempModel];

}
- (void)dealloc{

    [[SDWebImageManager sharedManager] cancelAll];;
}

#pragma mark -设置模板的标题/用户名样式
- (void)setupShareTitleStyle:(PPTemplateModel *)tempModel{
    
    [self.albumTitleLabel removeFromSuperview];
    
    UIFont *shareTitlefont = PPFONTSIZE(tempModel.shareModel.shareTitleFont);

    
    if ([tempModel.shareModel.shareTitleColor isKindOfClass:[NSString class]]) {
            self.albumTitleLabel.textColor = [UIColor colorWithHexString:tempModel.shareModel.shareTitleColor];
    }
    
    
    if (tempModel.orderNum == 2 || tempModel.orderNum == 3) {
        shareTitlefont = PFFontBold(tempModel.shareModel.shareTitleFont);
    }
    

    CGFloat lineSpace= kNormalShareTitleLineDistance/2-kLabelMargin;
    if (tempModel.orderNum == 2 || tempModel.orderNum == 3 ) {
        
        lineSpace = 8/2;
    }
    
    if (tempModel.orderNum == 6 || tempModel.orderNum == 7) {
        shareTitlefont = PFFontBold(tempModel.shareModel.shareTitleFont);
         lineSpace = 0;
    }
    
    //外阴影
    if (tempModel.orderNum == 4 || tempModel.orderNum == 5) {
        if (tempModel.orderNum == 4) {
            self.albumTitleLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
            shareTitlefont = PFFontBold(tempModel.shareModel.shareTitleFont);
        }
        if (tempModel.orderNum == 5 && [NSString isFontDownloaded:@"Songti SC"]) {
            shareTitlefont = PPFONT(@"Songti SC", tempModel.shareModel.shareTitleFont);
        }
        
        lineSpace = 8/2-kLabelMargin*2;
        self.albumTitleLabel.layer.shadowColor = [UIColor colorWithHexString:@"#000000"].CGColor;//阴影颜色
        self.albumTitleLabel.layer.shadowOffset = CGSizeMake(-0.5, -0.5);//偏移距离
        self.albumTitleLabel.layer.shadowOpacity = 0.5;//不透明度
        self.albumTitleLabel.layer.shadowRadius = 1.0;//半径
        

    }
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpace];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    //对齐样式
    if (tempModel.orderNum == 1 || tempModel.orderNum == 2 ||tempModel.orderNum == 4) {
        paragraphStyle.alignment = NSTextAlignmentLeft;
        self.userLabel.textAlignment = NSTextAlignmentLeft;
    }else{
        paragraphStyle.alignment = NSTextAlignmentCenter;
    }
    
    [self.albumTitleLabel changeTitleMutableParagraphStyle:paragraphStyle titleText:_albumModel.title labelFont:shareTitlefont];

    [self addSubview:self.albumTitleLabel];
    
//    self.userLabel.backgroundColor = RED;

    
    if (tempModel.orderNum == 4) {
        self.userLabel.font = PFFontBold([tempModel.shareModel.shareUserFont floatValue]);
    }else{
        self.userLabel.font = PPFONTSIZE([tempModel.shareModel.shareUserFont floatValue]);
    }
    
    if (tempModel.shareModel.shareUserColor) {
        self.userLabel.textColor = [UIColor colorWithHexString:tempModel.shareModel.shareUserColor];
    }
    if (tempModel.orderNum == 4 || tempModel.orderNum == 5) {
        if (tempModel.orderNum == 4) {
            self.userLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
             self.userLabel.font = PFFontBold([tempModel.shareModel.shareUserFont floatValue]);
        }
        
        if (tempModel.orderNum == 5 && [NSString isFontDownloaded:@"Songti SC"]) {
             self.userLabel.font = PPFONT(@"Songti SC",[tempModel.shareModel.shareUserFont floatValue]);
        }
        

        self.userLabel.layer.shadowColor = [UIColor colorWithHexString:@"#000000"].CGColor;//阴影颜色
        self.userLabel.layer.shadowOffset = CGSizeMake(-0.5, -0.5);//偏移距离
        self.userLabel.layer.shadowOpacity = 0.5;//不透明度
        self.userLabel.layer.shadowRadius = 1.0;//半径
    }
    if (tempModel.orderNum == 6 || tempModel.orderNum == 7) {
        
        self.userLabel.font = PFFontBold([tempModel.shareModel.shareUserFont floatValue]);
    }
    
    PPAccountProfiles *profiles = [PPAccountManager sharedInstance].account.profiles;
    //    self.albumModel.nickName = profiles.name;
    self.userLabel.text = profiles.name;
//    self.userLabel.text = self.albumModel.nickName;
    
    [self addSubview:self.userLabel];
    
}

#pragma mark - 调整分享页 标题的Y值
- (void)adjustShareAlbumtitleLabelH:(PPTemplateShareModel *)shareModel{
    CGFloat titleX = shareModel.shareTitleXaxis;
    CGFloat titleY = shareModel.shareTitleYaxis;
    CGFloat titleH = shareModel.shareTitleHeight;
    
    if ([self.albumTitleLabel labelText:self.albumModel.title width:shareModel.shareTitleWidth]) {
        //大于一行
        switch (self.tempModel.orderNum) {
            case 1:
            {
                titleY = shareModel.shareTitleYaxis - 3;
                titleH = shareModel.shareTitleHeight + 2;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 10;
                }
            }
                break;
            case 2:
            {
                titleY = shareModel.shareTitleYaxis - 1 - kLabelMargin;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 8 - kLabelMargin;
                }
                
                
            }
                break;
            case 3:
            {
                titleY = shareModel.shareTitleYaxis + 9 - 12;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 9 - kLabelMargin;
                }

            }
                break;
            case 4:
            {
                titleH = shareModel.shareTitleHeight + 8;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 8 - 14 - 14;
                }
                
            }
                break;
            case 5:
            {
                // 摄影/艺术
                titleY = shareModel.shareTitleYaxis - 3;
                titleH = shareModel.shareTitleHeight + 20;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 3 + 30;
                }
                
            }
                break;
            case 6:
            {
                titleX = shareModel.shareTitleXaxis + 35;
                titleY = shareModel.shareTitleYaxis - 64 - 40 - 10;
                
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 64;
                    titleX = shareModel.shareTitleXaxis;
                }
                
                titleH = shareModel.shareTitleHeight +46;

            }
                break;
            case 7:
            {
                // 摄影/艺术
                titleY = shareModel.shareTitleYaxis - 64 - 40 - 16;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 64 -5;
                }
                titleH = shareModel.shareTitleHeight +46;
                
            }
                
            default:
                break;
        }
        
    }else{
        switch (self.tempModel.orderNum) {
            case 1:
            {
                titleY = shareModel.shareTitleYaxis + 13;
                titleH = 25;
                
            }
                break;
            case 2:
            {
                titleY = shareModel.shareTitleYaxis - 1 - kLabelMargin;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 8;
                }
                
                
            }
                break;
            case 3:
            {
                titleY = shareModel.shareTitleYaxis + 9 - 12;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis + 9 - kLabelMargin;
                }
                
            }
                break;
            case 4:
            {
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 14;
                }
                
            }
                break;
            case 5:
            {
                // 摄影/艺术
                titleY = shareModel.shareTitleYaxis + 10;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 3 + 34;
                }
                
            }
                break;
            case 6:
            {
                titleX = shareModel.shareTitleXaxis + 35;
                titleY = shareModel.shareTitleYaxis - 64 - 20;
                if (IS_IPHONE_6_PLUS) {
                    titleX = shareModel.shareTitleXaxis;
                    titleY = shareModel.shareTitleYaxis - 23;
                }
                
            }
                break;
            case 7:
            {
                // 摄影/艺术
                titleY = shareModel.shareTitleYaxis - 64 - 25;
                if (IS_IPHONE_6_PLUS) {
                    titleY = shareModel.shareTitleYaxis - 37;
                }
                
            }
                break;
            default:
                break;
        }
    }
    
    self.albumTitleLabel.frame = CGRectMake(titleX,titleY, shareModel.shareTitleWidth,titleH);

}
#pragma mark -调整分享页用户名位置
- (void)adjustShareUserLabel:(PPTemplateShareModel *)shareM{

    
    CGFloat userLabelY = shareM.shareUserYaxis;
//    CGFloat userLabelH = shareM.shareUserHeight;
    switch (self.tempModel.orderNum) {
        case 3:
        {
            if (IS_IPHONE_6_PLUS) {
                userLabelY = shareM.shareUserYaxis - 2;
            }
            
        }
            break;
        case 4:
        {
             userLabelY = shareM.shareUserYaxis + 3;
            if (IS_IPHONE_6_PLUS) {
                userLabelY = shareM.shareUserYaxis + 8 - 14;
            }
            
        }
        break;
        case 5:
        {
            userLabelY = shareM.shareUserYaxis + 20;
            if (IS_IPHONE_6_PLUS) {
                userLabelY = shareM.shareUserYaxis + 32;
            }
        }
            break;
        case 6:
        {
            
//            userLabelY = shareM.shareUserYaxis -64;
//            if (IS_IPHONE_6_PLUS) {
//                userLabelY = shareM.shareUserYaxis -64;
//            }
           userLabelY = CGRectGetMaxY(self.albumTitleLabel.frame) + 10;
            if ([self.albumTitleLabel labelText:self.albumModel.title width:self.tempModel.shareModel.shareTitleWidth]) {
                userLabelY = CGRectGetMaxY(self.albumTitleLabel.frame) + 15/2;
                if (IS_IPHONE_6) {
                    userLabelY = CGRectGetMaxY(self.albumTitleLabel.frame) + 15/2 - 10;
                }
            }
        }
            break;
        case 7:
        {
            userLabelY = CGRectGetMaxY(self.albumTitleLabel.frame) + ([self.albumTitleLabel labelText:self.albumModel.title width:shareM.shareTitleWidth]?0:15);
        }
            break;
            
        default:
            break;
    }
    
    self.userLabel.frame = CGRectMake(shareM.shareUserXaxis,userLabelY, shareM.shareUserWidth, shareM.shareUserHeight);
    
}
- (void)updateCoverTitle:(NSString *)title{
    
    self.albumModel.title = title;
    
//    self.albumTitleLabel.text = title;
//    [self adjustShareUserLabel:self.tempModel];
    
//    if (self.albumModel.order == 1) {
//
//    }
//
//    self.albumTitleLabel.text = title;
    
    
    
}
@end
